package com.zhangmengyuan.medical.service.impl;

import com.zhangmengyuan.medical.dao.UserDao;
import com.zhangmengyuan.medical.entity.User;
import com.zhangmengyuan.medical.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public void save(User user) {
        userDao.save(user);
    }

    @Override
    public List<User> getAll() {
        return userDao.findAll();
    }

    @Override
    public User getById(Integer userId) {
        return userDao.findOne(userId);
    }
  /*@Override
  public void deleteUserById(Integer userId){ return userDao.delete(Integer userId);}*/

    @Override
    public User login(String username, String password) {
        User user = userDao.findByUserNameOrEmailOrPhone(username, username, username);
        if (user != null) {
            if (password.equals(user.getPassWord())) {
                return user;
            }
        }
        return null;
    }
}
